var $ = require('jquery');
var util = require('imutil');

var tpl = require('../tpl');
var i18n = require('../i18n');
var servant = require('../i18n/servant');
var bus = require('bus');

var defaults = {
    el: null,
    tmpl: tpl.chat2.timestamp()
};

var Timestamp = function(config){
    this.config = util.extend({}, defaults, config);
    this.elems = {};

    this.__init();
};

Timestamp.prototype = {
    __init: function(){
        this.elems.$el = $(this.config.el);
        this.elems.$timestamp = $(this.config.tmpl);
        this.elems.$chattime = $('.J-im-chattime', this.elems.$timestamp);

        //this.elems.$el.append(this.elems.$timestamp);
    },
    addTimestamp: function(data){
        this.elems.$el.append(this.elems.$timestamp.html(util.formatDate(data)));
    },
    addHIstoryTimestamp: function(data){
        this.elems.$el.prepend(this.elems.$timestamp.html(util.formatDate(data)));
    },
    isAddTimestamp: function(lastData){
        var nowdate = new Date();
        if(nowdate.getTime() - lastData>60000){
            return true;
        }
        return false;
    }
};

module.exports = Timestamp;